﻿Imports System.Text
Imports System.Data.OleDb
Public Class pontuacaoDAO

    Private sql As New StringBuilder
    Private i As Integer

    Public Function insereRegistro(ByVal pontuacao As pontuacaoVO) As Integer

        Dim numReg As Integer = 0
        sql.Clear()
        sql.Append("INSERT INTO PONTUACAO (ID_USUARIO,ID_REGISTRO,PONTUACAO,TIPO_OCORRENCIA)")
        sql.Append("VALUES")
        sql.Append("(@ID_USUARIO,@ID_REGISTRO,@PONTUACAO,@TIPO_OCORRENCIA)")
        Try
            Dim objConn As New conexao
            Dim oComando As New OleDbCommand(sql.ToString, objConn.abreConexao)
            With pontuacao
                oComando.Parameters.AddWithValue("@ID_USUARIO", .USUARIO.ID_USUARIO)
                oComando.Parameters.AddWithValue("@ID_REGISTRO", .REGISTRO.ID_REGISTRO)
                oComando.Parameters.AddWithValue("@PONTUACAO", .PONTUACAO)
                oComando.Parameters.AddWithValue("@TIPO_OCORRENCIA", .TIPO_OCORRENCIA)
                '  oComando.Parameters.AddWithValue("@DATA_ALTERACAO", Date.Parse(.DATA_ALTERACAO))
                i = oComando.ExecuteNonQuery
            End With
        Catch ex As Exception
            Throw ex
        End Try

        Return i

    End Function


    Public Function upDatePontuacao(ByVal usuario As Integer, _
                                    ByVal reg As registroVO) As Integer

        Dim numReg As Integer = 0
        Dim SQL As String
        Try


            If usuario <> reg.USUARIO.ID_USUARIO Then

                SQL = "UPDATE PONTUACAO SET ID_USUARIO=" & usuario & ",DATA_ALTERACAO='" & Now & "' WHERE ID_REGISTRO=" & reg.ID_REGISTRO
                'sql.Append("UPDATE PONTUACAO SET ID_USUARIO=@ID_USUARIO,DATA_ALTERACAO=@DATA_ALTERACAO WHERE ID_REGISTRO=@ID_REGISTRO")

                Dim objConn As New conexao
                Dim oComando As New OleDbCommand(SQL.ToString, objConn.abreConexao)



                'oComando.Parameters.AddWithValue("@ID_USUARIO", reg.USUARIO.ID_USUARIO)
                'oComando.Parameters.AddWithValue("@ID_REGISTRO", reg.ID_REGISTRO)
                'oComando.Parameters.Add(New OleDbParameter("@DATA_ALTERACAO", OleDbType.DBDate)).Value = Now

                i = oComando.ExecuteNonQuery
            Else
                i = 0
            End If

        Catch ex As Exception
            Throw ex
        End Try

        Return i

    End Function

End Class
